package com.cqie.hospitalescort.mapper;

import com.cqie.hospitalescort.entity.MedOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 订单信息 Mapper 接口
 * </p>
 *
 * @author gdy
 * @since 2025-02-18
 */
@Mapper
public interface MedOrderMapper extends BaseMapper<MedOrder> {

    /**
     * 获取指定日期的最大订单编号尾数
     *
     * @param dateStr 格式为 yyyyMMdd 的日期字符串
     * @return 最大的订单编号尾数
     */
    @Select("SELECT IFNULL(MAX(SUBSTRING_INDEX(order_code, '_', -1)), 0) FROM med_order WHERE order_code LIKE CONCAT('O_', #{dateStr}, '_%')")
    int getMaxOrderNumberByDate(@Param("dateStr") String dateStr);

}
